|
1
|
|
|
var chai = require('chai'); |
|
2
|
|
|
var sinonChai = require('sinon-chai') |
|
3
|
|
|
var expect = chai.expect |
|
4
|
|
|
chai.use(sinonChai) |
|
5
|
|
|
var sinon = require('sinon'); |
|
6
|
|
|
var path = require('path'); |
|
7
|
|
|
var fse = require('fs-extra'); |
|
8
|
|
|
|
|
9
|
|
|
var config = require('../../../src/cli').config |
|
10
|
|
|
config.set({root: path.join(process.cwd(), 'test', 'fixtures')}) |
|
11
|
|
|
|
|
12
|
|
|
var abeExtend = require('../../../src/cli').abeExtend; |
|
13
|
|
|
var cmsData = require('../../../src/cli').cmsData; |
|
14
|
|
|
var cmsTemplates = require('../../../src/cli').cmsTemplates; |
|
15
|
|
|
var coreUtils = require('../../../src/cli').coreUtils; |
|
16
|
|
|
var Manager = require('../../../src/cli').Manager; |
|
17
|
|
|
|
|
18
|
|
|
describe('cmsTemplates.prepare', function() { |
|
19
|
|
|
before( function(done) { |
|
20
|
|
|
Manager.instance.init() |
|
21
|
|
|
.then(function () { |
|
22
|
|
|
this.fixture = { |
|
23
|
|
|
visibleTrue: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-visible-true.html'), 'utf-8'), |
|
24
|
|
|
visibleFalse: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-visible-false.html'), 'utf-8'), |
|
25
|
|
|
text: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-text.html'), 'utf-8'), |
|
26
|
|
|
attribute: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-attribute.html'), 'utf-8'), |
|
27
|
|
|
attributeConcat: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-attribute-concat.html'), 'utf-8'), |
|
28
|
|
|
source: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-source.html'), 'utf-8'), |
|
29
|
|
|
each: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-each.html'), 'utf-8'), |
|
30
|
|
|
rawHandlebar: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-raw-handlebars.html'), 'utf-8') |
|
31
|
|
|
} |
|
32
|
|
|
done() |
|
33
|
|
|
|
|
34
|
|
|
}.bind(this)) |
|
35
|
|
|
}); |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* cmsTemplates.template.addAbeDataAttrForHtmlTag |
|
39
|
|
|
* |
|
40
|
|
|
*/ |
|
41
|
|
|
it('cmsTemplates.prepare.addAbeDataAttrForHtmlTag()', function() { |
|
42
|
|
|
// stub |
|
43
|
|
|
|
|
44
|
|
|
// test |
|
45
|
|
|
var template = cmsTemplates.prepare.addAbeDataAttrForHtmlTag(this.fixture.text) |
|
46
|
|
|
chai.expect(template.indexOf('data-abe-')).to.be.above(-1); |
|
47
|
|
|
}); |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* cmsTemplates.template.addAbeDataAttrForHtmlAttributes |
|
51
|
|
|
* |
|
52
|
|
|
*/ |
|
53
|
|
|
it('cmsTemplates.prepare.addAbeDataAttrForHtmlAttributes()', function() { |
|
54
|
|
|
// stub |
|
55
|
|
|
|
|
56
|
|
|
// test |
|
57
|
|
|
var template = cmsTemplates.prepare.addAbeDataAttrForHtmlAttributes(this.fixture.attribute) |
|
58
|
|
|
chai.expect(template.indexOf('data-abe-attr-')).to.be.above(-1); |
|
59
|
|
|
|
|
60
|
|
|
var templateConcat = cmsTemplates.prepare.addAbeDataAttrForHtmlAttributes(this.fixture.attributeConcat) |
|
61
|
|
|
chai.expect(templateConcat.indexOf('data-abe-attr-')).to.be.above(-1); |
|
62
|
|
|
}); |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* cmsTemplates.template.addAbeSourceComment |
|
66
|
|
|
* |
|
67
|
|
|
*/ |
|
68
|
|
|
it('cmsTemplates.prepare.addAbeSourceComment()', function() { |
|
69
|
|
|
// stub |
|
70
|
|
|
|
|
71
|
|
|
// test |
|
72
|
|
|
var template = cmsTemplates.prepare.addAbeSourceComment(this.fixture.source, |
|
73
|
|
|
{ |
|
74
|
|
|
abe_source: { |
|
75
|
|
|
data_key: [{title: "test"}] |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
) |
|
79
|
|
|
|
|
80
|
|
|
chai.expect(template.indexOf('<!-- [[')).to.be.above(-1); |
|
81
|
|
|
chai.expect(template.indexOf('-->')).to.be.above(-1); |
|
82
|
|
|
}); |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* cmsTemplates.template.addAbeHtmlTagBetweenAbeTags |
|
86
|
|
|
* |
|
87
|
|
|
*/ |
|
88
|
|
|
it('cmsTemplates.prepare.addAbeHtmlTagBetweenAbeTags()', function() { |
|
89
|
|
|
// stub |
|
90
|
|
|
|
|
91
|
|
|
// test |
|
92
|
|
|
var template = cmsTemplates.prepare.addAbeHtmlTagBetweenAbeTags(this.fixture.text) |
|
93
|
|
|
chai.expect(template.indexOf('<abe>{{')).to.be.above(-1); |
|
94
|
|
|
chai.expect(template.indexOf('}}</abe>')).to.be.above(-1); |
|
95
|
|
|
}); |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* cmsTemplates.template.replaceAbeEachIndex |
|
99
|
|
|
* |
|
100
|
|
|
*/ |
|
101
|
|
|
it('cmsTemplates.prepare.replaceAbeEachIndex()', function() { |
|
102
|
|
|
// stub |
|
103
|
|
|
|
|
104
|
|
|
// test |
|
105
|
|
|
var template = cmsTemplates.prepare.replaceAbeEachIndex('[index].') |
|
106
|
|
|
chai.expect(template).to.be.equal('{{@index}}-'); |
|
107
|
|
|
}); |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* cmsTemplates.template.removeHiddenAbeTag |
|
111
|
|
|
* |
|
112
|
|
|
*/ |
|
113
|
|
|
it('cmsTemplates.prepare.removeHiddenAbeTag()', function() { |
|
114
|
|
|
// stub |
|
115
|
|
|
|
|
116
|
|
|
// test |
|
117
|
|
|
var template = cmsTemplates.prepare.removeHiddenAbeTag(this.fixture.visibleFalse) |
|
118
|
|
|
chai.expect(template).to.be.equal(""); |
|
119
|
|
|
|
|
120
|
|
|
// test |
|
121
|
|
|
var template2 = cmsTemplates.prepare.removeHiddenAbeTag(this.fixture.visibleTrue) |
|
122
|
|
|
chai.expect(template2.indexOf('{{abe')).to.be.above(-1); |
|
123
|
|
|
}); |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* cmsTemplates.template.removeHandlebarsRawFromHtml |
|
127
|
|
|
* |
|
128
|
|
|
*/ |
|
129
|
|
|
it('cmsTemplates.prepare.removeHandlebarsRawFromHtml()', function() { |
|
130
|
|
|
// stub |
|
131
|
|
|
|
|
132
|
|
|
// test |
|
133
|
|
|
var template = cmsTemplates.prepare.removeHandlebarsRawFromHtml(this.fixture.rawHandlebar) |
|
134
|
|
|
chai.expect(template).to.be.equal("test"); |
|
135
|
|
|
}); |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* cmsTemplates.template.splitEachBlocks |
|
139
|
|
|
* |
|
140
|
|
|
*/ |
|
141
|
|
|
it('cmsTemplates.prepare.splitEachBlocks()', function() { |
|
142
|
|
|
// stub |
|
143
|
|
|
|
|
144
|
|
|
// test |
|
145
|
|
|
var blocks = cmsTemplates.prepare.splitEachBlocks(this.fixture.each) |
|
146
|
|
|
chai.expect(blocks.length).to.be.above(0); |
|
147
|
|
|
}); |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* cmsTemplates.template.indexEachBlocks |
|
151
|
|
|
* |
|
152
|
|
|
*/ |
|
153
|
|
|
it('cmsTemplates.prepare.indexEachBlocks()', function() { |
|
154
|
|
|
// stub |
|
155
|
|
|
|
|
156
|
|
|
// test |
|
157
|
|
|
var template = cmsTemplates.prepare.indexEachBlocks(this.fixture.each, false) |
|
158
|
|
|
chai.expect(template.indexOf('data-abe-block')).to.be.above(-1); |
|
159
|
|
|
chai.expect(template.indexOf('<!-- [[test]]')).to.be.above(-1); |
|
160
|
|
|
}); |
|
161
|
|
|
}); |
|
162
|
|
|
|